package com.atguigu.tingshu.album.client;

import com.atguigu.tingshu.album.mapper.BaseCategory1Mapper;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategory1Service;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiguCache;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/***
 * 专辑微服务内部调用
 */
@RestController
@RequestMapping("/client/album/albumInfo")
public class AlbumClientController {
    @Autowired
    private AlbumInfoService albumInfoService;
    @Autowired
    private BaseCategoryService baseCategoryService;

    @GuiguCache(prefix = "getBaseCategoryView:")
    @GetMapping("/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable("category3Id")Long category3Id){
        return baseCategoryService.getById(category3Id);
    }


    /**
     * 根据id查专辑
     * @param albumId
     * @return
     */
//    @GuiguCache(prefix = "getAlbumInfo:")
    @GetMapping("/getAlbumInfo/{albumId}")
    public AlbumInfo getAlbumInfo(@PathVariable("albumId")Long albumId){
        return albumInfoService.getById(albumId);
    }



    /**
     * 获取专辑标签list
     * @param albumId
     * @return
     */
    @GuiguCache(prefix = "getAlbumAttributeValueList:")
    @GetMapping("/getAlbumAttributeValueList/{albumId}")
    public List<AlbumAttributeValue> getAlbumAttributeValueList(@PathVariable("albumId")Long albumId){
        return albumInfoService.getAlbumAttributeValueList(albumId);
    }


    /**
     * 获取专辑统计信息
     * @param albumId
     * @return
     */
    @GuiguCache(prefix = "getAlbumStatMap:")
    @GetMapping("/getAlbumStatMap/{albumId}")
    public Map<String,Object> getAlbumStatMap(@PathVariable("albumId")Long albumId){
        return albumInfoService.getAlbumStatMap(albumId);
    }


    /**
     * 内部调用接口：
     * 搜索首页根据1级分类id获取3级分类top7
     * @param category1Id
     * @return
     */
    @GuiguCache(prefix = "findTopBaseCategory3:")
    @GetMapping("/findTopBaseCategory3/{category1Id}")
    public List<BaseCategory3> findTopBaseCategory3(@PathVariable("category1Id") Long category1Id){
        return baseCategoryService.findTopBaseCategory3(category1Id);
    }

    @Autowired
    private RBloomFilter rBloomFilter;

    /**
     * 判断布隆过滤器中是否包含该专辑数据
     * @param albumId
     * @return
     */
    @GetMapping("/getAlbumFromBloom/{albumId}")
    public Boolean getAlbumFromBloom(@PathVariable("albumId")Long albumId){
        return rBloomFilter.contains("getAlbumInfo:" + Arrays.asList(albumId.toString()));
    }

    @Autowired
    private BaseCategory1Service baseCategory1Service;

    /**
     * 查询所有一级分类列表
     * @return
     */
    @GetMapping("/getAllBaseCategory1")
    List<BaseCategory1> getAllBaseCategory1(){
        return baseCategory1Service.list();
    }



}
